package com.xplay.xpocker.room.mahjong.action;

import com.xplay.xpocker.dvo.AbstractRoom;
import com.xplay.xpocker.entity.GameRuMahjongLogs;
import com.xplay.xpocker.room.mahjong.AbstractMahjongMessageStrategy;
import com.xplay.xpocker.room.mahjong.MahjongActionHandler;
import com.xplay.xpocker.room.mahjong.dto.MahjongActionEnum;
import com.xplay.xpocker.room.mahjong.dto.MahjongMessage;
import com.xplay.xpocker.room.mahjong.dto.MahjongRoomInfo;
import com.xplay.xpocker.room.mahjong.dto.MahjongRoomRule;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class PassAction extends AbstractMahjongMessageStrategy<AbstractRoom<MahjongRoomRule, MahjongRoomInfo, GameRuMahjongLogs>, MahjongMessage> {
    @Autowired
    private MahjongActionHandler mahjongActionHandler;

    @Override
    protected String strategyName() {
        return MahjongActionEnum.PASS.getAction();
    }

    // TODO 碰牌需要判断有没有人要胡牌 杠牌优先级低于胡牌
    @Override
    public boolean doMessage(AbstractRoom<MahjongRoomRule, MahjongRoomInfo,GameRuMahjongLogs> roomInfo, MahjongMessage messageInfo) {
        /**
         * 当前用户直接喊过
         * 判断是否有用户 需要处理 待处理事件
         */
        if (checkExistsWaitCompleted()) {
            return false;
        }
        boolean loadingCompleted = doLoadingCompleted(roomInfo);
        // 说明有待处理事件 不要执行发牌,让内部自行消化
        if (loadingCompleted) {
            return false;
        }
        /**
         * 没有待处理事件
         * 判断是否存在处理事件
         */
        dealCard(roomInfo.getGameInfo().getExportUserSeq(), true);
        return true;
    }

}
